package com.fanfq.itrack.ui;

import java.util.List;

import com.fanfq.itrack.R;
import com.fanfq.itrack.model.Feed;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class FeedAdapter extends BaseAdapter{

	private LayoutInflater mInflater;
	private Context mContext;
	private List<Feed> mlist;
	
	public FeedAdapter(Context context,List<Feed> list){
		this.mInflater = LayoutInflater.from(context);
		this.mContext = context;
		this.mlist = list;
	}
	
	public int getCount() {
		return mlist.size();
	}

	public Object getItem(int arg0) {
		return arg0;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = mInflater.inflate(R.layout.feed_list_item, null);
		TextView title = (TextView)convertView.findViewById(R.id.title);
		TextView name = (TextView)convertView.findViewById(R.id.name);
		TextView distance = (TextView)convertView.findViewById(R.id.distance);
		TextView elevation = (TextView)convertView.findViewById(R.id.elevation);
		
		if(mlist.get(position).isMe()){
			title.setText(mlist.get(position).getTitle());
			name.setText(mlist.get(position).getDate());
			distance.setText(mlist.get(position).getDistance());
			elevation.setText(mlist.get(position).getElevation());
		}else{
			title.setText(mlist.get(position).getDate());
			name.setText(mlist.get(position).getUserName());
			distance.setText(mlist.get(position).getDistance());
			elevation.setText(mlist.get(position).getElevation());
		}
		
		return convertView;
	}

}
